﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Admin.Models;
using Admin.Common;

namespace Admin.Controllers
{
    public class TestController : BaseController
    {
        private BookingDBEntities db = new BookingDBEntities();

        //
        // GET: /Test/

        public PartialViewResult Index()
        {
            var tblhotels = db.TblHotels.Include(t => t.TblCity).Include(t => t.TblCountry).Include(t => t.TblUserProfile);
            return PartialView("Index",tblhotels.ToList());
        }

        //
        // GET: /Test/Details/5

        public ActionResult Details(int id = 0)
        {
            TblHotel tblhotel = db.TblHotels.Find(id);
            if (tblhotel == null)
            {
                return HttpNotFound();
            }
            return View(tblhotel);
        }

        //
        // GET: /Test/Create

        public ActionResult Create()
        {
            ViewBag.CityID = new SelectList(db.TblCities, "CityID", "CityName");
            ViewBag.CountryID = new SelectList(db.TblCountries, "CountryID", "CountryName");
            ViewBag.ContactNameID = new SelectList(db.TblUserProfiles, "UserID", "UserName");
            return View();
        }

        //
        // POST: /Test/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(TblHotel tblhotel)
        {
            if (ModelState.IsValid)
            {
                db.TblHotels.Add(tblhotel);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.CityID = new SelectList(db.TblCities, "CityID", "CityName", tblhotel.CityID);
            ViewBag.CountryID = new SelectList(db.TblCountries, "CountryID", "CountryName", tblhotel.CountryID);
            ViewBag.ContactNameID = new SelectList(db.TblUserProfiles, "UserID", "UserName", tblhotel.ContactNameID);
            return View(tblhotel);
        }

        //
        // GET: /Test/Edit/5

        public ActionResult Edit(int id = 0)
        {
            TblHotel tblhotel = db.TblHotels.Find(id);
            if (tblhotel == null)
            {
                return HttpNotFound();
            }
            ViewBag.CityID = new SelectList(db.TblCities, "CityID", "CityName", tblhotel.CityID);
            ViewBag.CountryID = new SelectList(db.TblCountries, "CountryID", "CountryName", tblhotel.CountryID);
            ViewBag.ContactNameID = new SelectList(db.TblUserProfiles, "UserID", "UserName", tblhotel.ContactNameID);
            return View(tblhotel);
        }

        //
        // POST: /Test/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(TblHotel tblhotel)
        {
            if (ModelState.IsValid)
            {
                db.Entry(tblhotel).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.CityID = new SelectList(db.TblCities, "CityID", "CityName", tblhotel.CityID);
            ViewBag.CountryID = new SelectList(db.TblCountries, "CountryID", "CountryName", tblhotel.CountryID);
            ViewBag.ContactNameID = new SelectList(db.TblUserProfiles, "UserID", "UserName", tblhotel.ContactNameID);
            return View(tblhotel);
        }

        //
        // GET: /Test/Delete/5

        public ActionResult Delete(int id = 0)
        {
            TblHotel tblhotel = db.TblHotels.Find(id);
            if (tblhotel == null)
            {
                return HttpNotFound();
            }
            return View(tblhotel);
        }

        //
        // POST: /Test/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            TblHotel tblhotel = db.TblHotels.Find(id);
            db.TblHotels.Remove(tblhotel);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}